//package org.javaboy.meeting.datasource.config;
//
//import org.javaboy.meeting.datasource.constants.DataSourceConstants;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.context.annotation.PropertySource;
//
//import javax.sql.DataSource;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 动态数据源配置
// *
// **/
//// 添加此配置，否则 报`The dependencies of some of the beans in the application context form a cycle`
////@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
//@Configuration
//@PropertySource("classpath:resources/db.properties")
////@MapperScan(basePackages = "me.mason.demo.dynamicdatasource.mapper")
//public class DynamicDataSourceConfig {
//    @Bean(DataSourceConstants.DS_KEY_MASTER)
//    @ConfigurationProperties(prefix = "db.master")
//    public DataSource masterDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(DataSourceConstants.DS_KEY_SLAVE)
//    @ConfigurationProperties(prefix = "db.master")
//    public DataSource slaveDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean
//    @Primary
//    public DataSource dynamicDataSource() {
//        Map<Object, Object> dataSourceMap = new HashMap<>(2);
//        dataSourceMap.put(DataSourceConstants.DS_KEY_MASTER, masterDataSource());
//        dataSourceMap.put(DataSourceConstants.DS_KEY_SLAVE, slaveDataSource());
//        //设置动态数据源
//        DynamicDataSource dynamicDataSource = new DynamicDataSource();
//        dynamicDataSource.setTargetDataSources(dataSourceMap);
//        dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
//
//        return dynamicDataSource;
//    }
//
//}
